package com.yoda.mall.mysql.api;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoda.mall.api.CouponHistoryApi;
import com.yoda.mall.model.entity.sms.Coupon;
import com.yoda.mall.model.entity.sms.CouponHistory;
import com.yoda.mall.mysql.mapper.CouponHistoryMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class CouponHistoryApiImpl implements CouponHistoryApi {
    @Autowired
    private CouponHistoryMapper couponHistoryMapper;

    @Override
    public Page<CouponHistory> getCouponHistoryListPage(Long couponId, String orderSn, Integer pageNum, Integer pageSize, Integer useStatus) {
        Page<CouponHistory> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CouponHistory> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotNull(couponId), CouponHistory::getCouponId, couponId);
        lqw.like(StrUtil.isNotEmpty(orderSn), CouponHistory::getOrderSn, orderSn);
        lqw.eq(ObjectUtil.isNotNull(useStatus), CouponHistory::getUseStatus, useStatus);
        couponHistoryMapper.selectPage(page, lqw);
        return page;
    }
}
